<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
	<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<body>
  <ul class="forminfo" style="margin-top: 20px;">
  		<li><label>选择类型</label><div class="label-light">
  											<span class="radio_first" id=""><input type="radio" name="xzlx" id="" value="0" checked="checked" onclick="news();"/>新增企业</span><span class="radio_second" id=""><input type="radio" name="xzlx" id="" onclick="used();" value="1" />已有企业</span>
  		                            </div>
  		</li>
  		<div id="new"> 
    	<li><label>单位名称</label><input name="Name" type="text" class="dfinput" maxlength="20"></li>
    	<li><label>单位地址</label>省份：<select id="dpselect1" name="TheProvince" class="forminfo_select" onchange="selectChanged();">
							<c:forEach items="${provinceList}" var="province">
							<option value="${province.provinceId }" >${province.provinceName }</option>
						</c:forEach>
						
					</select>
							城市：<select id="TheCity1" name="TheCity" class="forminfo_select" >
						<c:forEach items="${cityList}" var="city">
							<option value="${city.cityId }"  >${city.cityName }</option>
						</c:forEach>
						
					</select>
				<input name="TheAddress" type="text" class="dfinput" placeholder="具体地址" style="margin-left:96px;margin-top:10px;" maxlength="40">
    	</li>
    	<li><label>单位联系人</label><input name="TheContact" type="text" class="dfinput" maxlength="4" id="TheContact"></li>
    	<li><label>电话</label><input name="TheContactPhone" id="TheContactPhone" type="text" class="dfinput" maxlength="15" onblur="phoneOnblur()"></li>
    	 <li><label>单位简介</label><textarea class="long_text long_text2" name="TheIntroduce" maxlength="100"></textarea></li>
    	 </div>
    	 <div id="used"> 
    	 <li><label>所属区域</label>选择省份：<select id="dpselect" name="TheProvince" class="forminfo_select" onchange="TheProvince();">
							<c:forEach items="${provinceList}" var="province">
							<option value="${province.provinceId }" >${province.provinceName }</option>
						</c:forEach>
					</select>
							选择城市：<select id="TheCity" name="TheCity" class="forminfo_select" onchange="TheCity();">
							<c:forEach items="${cityList}" var="city">
							<option value="${city.cityId }"  >${city.cityName }</option>
						</c:forEach>
					</select>
					<div style="margin-left:96px;margin-top:10px;" maxlength="40">
				选择单位：<select id="EnterpriseId" name="EnterpriseId" class="forminfo_select1" >
						<c:forEach items="${enterpriseinfoList}" var="enterpriseinfoList">
							<option value="${enterpriseinfoList.id }" >${enterpriseinfoList.name }</option>
						</c:forEach>
					</select>
					</div>
    	</li>
    	 </div>
    	 <li><label>特殊岗位需求</label><textarea class="long_text long_text2" name="EnterpriseSpecialReq" maxlength="100"></textarea></li>
	<li><label>&nbsp;</label><input name="" type="button" class="btn" onclick="submitForm()" value="确认保存"></li>
    </ul>
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="js/jquery.tips.js"></script>
	<script type="text/javascript" src="layer/layer.js" ></script>
    <script type="text/javascript">
$('.tablelist tbody tr:odd').addClass('odd');
var JobId = '${id}';
	$("#used").hide();
	function news() {
		$("#used").hide();
		$("#new").show();
	}
	function used() {
		$("#used").show();
		$("#new").hide();
	}
	function selectChanged() {
		 var ele=document.getElementById('dpselect1');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		 	$.ajax({
			type: "POST",
			url: "enterpriseinfo/province.do",
			data: { ProvinceId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#TheCity1").empty();
				for(var i in data.cityList){  
					var $str = "<option value="+data.cityList[i].cityId +">"+data.cityList[i].cityName +"</option>";
					$("#TheCity1").append($str);  	 
				}}
			})
			}
	function TheProvince() {
		 var ele=document.getElementById('dpselect');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		 	$.ajax({
			type: "POST",
			url: "jobinfo/province.do",
			data: { ProvinceId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#TheCity").empty();
				for(var i in data.cityList){  
					var $str = "<option value="+data.cityList[i].cityId +">"+data.cityList[i].cityName +"</option>";
					$("#TheCity").append($str);  	 
				}
				$("#EnterpriseId").empty();
				for(var i in data.enterpriseinfoList){  
					var $str1 = "<option value="+data.enterpriseinfoList[i].id +">"+data.enterpriseinfoList[i].name +"</option>";
					$("#EnterpriseId").append($str1);  	 
				}
			}
			})
			}
	function TheCity() {
		 var ele=document.getElementById('TheCity');
		  	var index=ele.selectedIndex;
		 	 var val=ele.options[index].value;
		 	$.ajax({
			type: "POST",
			url: "jobinfo/city.do",
			data: { cityId : val},
			async: true,
			dataType: "json",
			success: function(data) {
				$("#EnterpriseId").empty();
				for(var i in data.enterpriseinfoList){  
					var $str = "<option value="+data.enterpriseinfoList[i].id +">"+data.enterpriseinfoList[i].name +"</option>";
					$("#EnterpriseId").append($str);  	 
				}
			}
		})
	}
	function phoneOnblur(){
	 	var inp = document.getElementById("TheContactPhone");
		var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
		var result = reg.test(inp.value);
		if (!result) {
			showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
			return false;
		}
	}
	function submitForm() {
		var value  = $('input[name="xzlx"]:checked').val();
	if(value==0){
		if ($("input[name='Name']").val() == "") {
			showTips($("input[name='Name']"), '请填写单位名称!');
			return false;
		}
		if ($("input[name='TheAddress']").val() =="") {
			showTips($("input[name='TheAddress']"), '请填写单位具体地址!');
			return false;
		}
		if ($("input[name='TheContact']").val() =="") {
			showTips($("input[name='TheContact']"), '请填写单位联系人!');
			return false;
		}
		if ($("input[name='TheContactPhone']").val() =="") {
			showTips($("input[name='TheContactPhone']"), '请填写电话!');
			return false;
		}
		if ($("textarea[name='TheIntroduce']").val() == "") {
			showTips($("textarea[name='TheIntroduce']"), '请填写单位简介!');
			return false;
			}
		if ($("textarea[name='EnterpriseSpecialReq']").val() == "") {
			showTips($("textarea[name='EnterpriseSpecialReq']"), '请填写特殊岗位需求!');
			return false;
			}
		var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
		var result = reg.test($("input[name='TheContactPhone']").val());
		if (!result) {
			showTips($("input[name='TheContactPhone']"), '手机号格式不对，请重新输入!！');
			return false;
		}
			var ele = document.getElementById('dpselect1');
			var index = ele.selectedIndex;
			var val = ele.options[index].value;
			var TheCity = document.getElementById('TheCity1');
			var index1 = TheCity.selectedIndex;
			var val1 = TheCity.options[index1].value;
			$.ajax({
				type : "POST",
				url : "jobinfo/enterpriseinfo_save.do",
				data : {
					JobId : JobId,
					Name : $("input[name='Name']").val(),
					provinceId :val,
					cityId : val1,
					TheAddress : $("input[name='TheAddress']").val(),
					TheContact : $("input[name='TheContact']").val(),
					TheContactPhone : $("input[name='TheContactPhone']").val(),
					TheIntroduce : $("textarea[name='TheIntroduce']").val(),
					EnterpriseSpecialReq : $("textarea[name='EnterpriseSpecialReq']").val()
				},
				async : true,
				dataType : "json",
				success : function(data) {
					if ("success" == data.result) {
						parent.closeAll();
					} else {
						layer.alert('添加失败!', {
							skin : 'layer-ext-moon'
						});
					}
				}
			});
		}else{
			var ele = document.getElementById('EnterpriseId');
			var index = ele.selectedIndex;
			var val = ele.options[index].value;
			if ($("textarea[name='EnterpriseSpecialReq']").val() == "") {
				showTips($("textarea[name='EnterpriseSpecialReq']"), '请填写特殊岗位需求!');
				return false;
				}
			$.ajax({
				type : "POST",
				url : "jobinfo/jobenterprise_save.do",
				data : {
					JobId : JobId,
					EnterpriseId : val,
					EnterpriseSpecialReq : $("textarea[name='EnterpriseSpecialReq']").val()
				},
				async : true,
				dataType : "json",
				success : function(data) {
					if ("success" == data.result) {
						layer.alert('添加成功!', {
							skin : 'layer-ext-moon'
						}, function() {
							layer.closeAll(); 
						});
					} else {
						layer.alert('添加失败!', {
							skin : 'layer-ext-moon'
						});
					}
				}
			});
		}
		}
	function showTips(obj,tips) {
		obj.tips({
			side:3,
	        msg:tips,
	        bg:'#e69138',
	        time:2
	    });
	}
</script>